package com.ll.notice.Factory.impl;

import com.ll.notice.Factory.HospitalFactory;
import com.ll.notice.entity.SmsNotice;
import com.ll.notice.ws.client.shunde.*;
import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

public class ShundeHospitalFactoryImpl implements HospitalFactory {

    private final static Logger log = Logger.getLogger(ShundeHospitalFactoryImpl.class);
    @Override
    public void sendSms(SmsNotice smsNotice) {


        MTPacks mtPacks = new MTPacks();
        mtPacks.setMsgType(1);
        mtPacks.setCustomNum("13801");
        mtPacks.setSendType(1);
        mtPacks.setDistinctFlag(true);
        mtPacks.setRemark("");

        String mobiles = smsNotice.getReceiverMobile();
        log.info("手机号：" +mobiles);
        String smsContent = smsNotice.getSmsContent();
        log.info("通知内容：：" +smsContent);
        String[] mobileArray = mobiles.split(",");
        List<String> mobilesList = Arrays.asList(mobileArray);
        log.info("电话号码集合:"+mobilesList);
        mobilesList.stream().forEach(mobile -> {
            log.info("电话号码:"+mobile);
            WebService webService = new WebService();
            WebServiceSoap webServiceSoap = webService.getWebServiceSoap();

            ArrayOfMessageData arrayOfMessageData = new ArrayOfMessageData();
            List<MessageData> list = new ArrayList<>();
            MessageData messageData = new MessageData();
            messageData.setContent(smsContent);
            messageData.setPhone(mobile);
            messageData.setVipFlag(true);
            list.add(messageData);
            arrayOfMessageData.setMessageData(list);
            mtPacks.setMsgs(arrayOfMessageData);
            log.info("mtPacks信息:"+mtPacks);
            GsmsResponse gsmsResponse = webServiceSoap.post("ygxt","PvpGthm8",mtPacks);
            log.info("消息返回体：" + gsmsResponse);
        });

    }
}
